package com.thread;

public class SyncApiDemo {
    public static void main(String[] args) {
        // StringBuilder在多线程里面不安全

        StringBuilder sb = new StringBuilder();
        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                sb.append("abc");
            }
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                sb.append("def");
            }
        }).start();

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(sb.length());
    }
}
